"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Device extends Model {
    static associate(models) {
      Device.hasMany(models.DeviceInfo, {
        foreignKey: "deviceId",
      });
      Device.belongsTo(models.Type, {
        foreignKey: "typeId",
      });
      Device.belongsTo(models.Brand, {
        foreignKey: "brandId",
      });
      Device.hasMany(models.Rating, {
        foreignKey: "rating",
      });
      Device.hasMany(models.BasketDivice, {
        foreignKey: "deviceId",
      });
    }
  }
  Device.init(
    {
      name: DataTypes.STRING,
      price: DataTypes.INTEGER,
      rating: DataTypes.INTEGER,
      img: DataTypes.STRING,
      typeId: DataTypes.INTEGER,
      brandId: DataTypes.INTEGER,
    },
    {
      sequelize,
      modelName: "Device",
    }
  );
  return Device;
};
